//家族js


function showInfo(text) {
    $("body").addClass("overflow-hidden");
    $(".info-text").html(text);
    $(".modal-info").fadeIn(300);

    setTimeout(function () {
        $("body").removeClass("overflow-hidden");
        $(".modal-info").fadeOut(300);
    }, 1000);
}
$(".info-sure").click(function (e) {
    e.preventDefault();
    $("body").removeClass("overflow-hidden");
    $(".modal-info").hide();
});

function openHref(url) {
    $(".info-sure-2").click(function (e) {
        e.preventDefault();
        window.location.href = url;
    });
}
(function ($) {
    //获取url参数的封装函数
    //decodeURI() 和 decodeURIComponent()
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&|#)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return decodeURIComponent(r[2]);
        }
        return null;
    };
    $.mygetUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");

        var r = window.location.hash.substr(1).match(reg);
        if (r != null) {
            return decodeURIComponent(r[2]);
        }
        return null;
    };
})(jQuery);


var server = 'http://139.199.23.160:8080/qmzb';
var page = 1; //当前页
var isEnd = false; //是否到底
var isLoading = false; //是否加载下一页
var touch_py = 0;
var rate = 0;

$("body")[0].addEventListener('touchmove', function (ev) {

    var screenhight = window.screen.height;
    window.onscroll = function () {
        if (screenhight + document.body.scrollTop > parseFloat(document.body.scrollHeight) + 100) {
            $(" #pullUp .pullUpIcon-down ").addClass("down");
            isLoading = true;
        } else {

            isLoading = false;
        }
    }

});

$("body")[0].addEventListener('touchend', function (ev) {

    if (isLoading & !isEnd) {
        $(" #pullUp .pullUpIcon-down ").removeClass("down").hide();
        $(" #pullUp .pullUpIcon-loading ").show();
        FamilyList.dataInit();
        //加载下一页

        isLoading = false;
    }




});
 var keyword = $.getUrlParam("id");

var FamilyList = {

    SearchdataLoadFUC: function (keyword, page) {
        var form_2 = new FormData();
        form_2.append("id", keyword);
        form_2.append("page", page);
        fetch(server + "/check/getFamilyList", {
            method: 'POST',
            //headers: myHeaders,
            mode: 'cors',
            cache: 'default',
            body: form_2
        }).then(function (response) {
            return response.json();
        }).then(function (data) {
            if (data.code == 200) {

                var element = data.data.list[0];

                $(".js_family_name").html(element.familyName);
                $(".js_family_income").html(element.monthTotalTicket + "民票")
                $(".js_family_id").html("ID " + element.id);
                $(".js_family_notice").html(element.notic);
                $(".js_family_det").html(element.declaration)



            } else {
                //失败
                showInfo("服务器异常");
            }
        });
    },
    familyID: null,
    search: function () {

      
        var login_uid = $.getUrlParam("login_uid");

        this.familyID = keyword;

        var page = 1;

        FamilyList.SearchdataLoadFUC(keyword, page);
        $(".js_getmore").click(function (e) {
            e.preventDefault();
            if ($(this).hasClass("active")) {
                $(this).removeClass("active").html("查看更多").parent().siblings("div.family-row-content").css("height", "1.2rem");

            } else {
                $(this).addClass("active").html("收起").parent().siblings("div.family-row-content").css("height", "auto");
            }

        });


        //提交
        $(".js_apply_btn").click(function (e) {
            e.preventDefault();
            var form_2 = new FormData();
            form_2.append("login_uid", login_uid);
            form_2.append("familyid",  FamilyList.familyID);
            fetch(server + "/check/addApply", {
                method: 'POST',
                //headers: myHeaders,
                mode: 'cors',
                cache: 'default',
                body: form_2
            }).then(function (response) {
                return response.json();
            }).then(function (data) {
                if (data.code == 200) {
                 
                    window.location.href="family_apply_ing.html";
                }else{
                     showInfo(data.message);
                  
                }
            })
        });
    }

};



$(function () {

    FamilyList.search();
});